import java.io.*;
import java.net.*;

public class EchoServer {
	public static final int PORT=7777;
	
	public static void main(String args[]) throws IOException {
		ServerSocket servSock=new ServerSocket(PORT);
		
		while (true) {
			Socket s=servSock.accept();
		
			BufferedReader br=new BufferedReader(
				new InputStreamReader(
						s.getInputStream(), "UTF-8"));
		
			String richiesta=br.readLine();
			System.out.println("Ricevuta richiesta: "+richiesta);
		
			PrintWriter pw=new PrintWriter(
				new OutputStreamWriter(
						s.getOutputStream(), "UTF-8"));
			pw.print(richiesta);
			pw.println(richiesta);
			pw.flush();
		
			s.close();
		}
				
	}

}
